<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>论坛详情</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="{{ static('images/logo.ico') }}"/>
    <meta name="keywords" content="小宅社区">
    <meta name="description" content="小宅社区">
    <link rel="stylesheet" href={{ static('js/layui/css/layui.css') }}>
    {#  <link rel="stylesheet" href="../res/css/global.css">#}
    <link rel="stylesheet" href={{ static('css/global.css') }}>
</head>
<body>
<meta name="referrer" content="no-referrer">
<div class="fly-header layui-bg-black">
    <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
    <div class="layui-container">
        <a class="fly-logo" href="/">
            <img src="../../static/res/images/logo.png" alt="layui">
        </a>

        <ul class="layui-nav fly-nav-user" id="ul_user">

            <!-- 登入后的状态 -->
            {% if user.username %}
                <li class="layui-nav-item">
                    <a class="fly-nav-avatar" href="javascript:;">
                        <cite class="layui-hide-xs">{{ user.username }}</cite>
                        <i class="iconfont icon-renzheng layui-hide-xs" title="认证信息：南神"></i>
                        {% if user.is_vip != 0 %}
                            <i class="layui-badge fly-badge-vip layui-hide-xs">VIP{{ user.is_vip }}</i>
                        {% endif %}
                        <img src="{{ user.images_url }}">
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="/user/set"><i class="layui-icon">&#xe620;</i>基本设置</a></dd>
                        <dd><a href="/user/follow"><i class="iconfont icon-tongzhi" style="top: 4px;"></i>我的关注</a></dd>
                        <dd><a href="/user/home?u={{ user.id }}"><i class="layui-icon"
                                                                    style="margin-left: 2px; font-size: 22px;">&#xe68e;</i>我的主页</a>
                        </dd>
                        <hr style="margin: 5px 0;">
                        <dd><a href="/user/logout" style="text-align: center;">退出</a></dd>
                    </dl>
                </li>
            {% else %}
                <!-- 未登入的状态 -->
                <li class="layui-nav-item">
                    <a class="iconfont icon-touxiang layui-hide-xs" href="/login"></a>
                </li>
                <li class="layui-nav-item">
                    <a href="/login">登录</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/reg">注册</a>
                </li>
            {% endif %}
        </ul>
    </div>
</div>

<div class="layui-hide-xs">
    <div class="fly-panel fly-column">
        <div class="layui-container">
            <ul class="layui-clear">
                <li class="layui-hide-xs"><a href="/">首页</a></li>
                <li><a href="/zy?are=tw">提问</a></li>
                <li><a href="/zy?are=fx">分享<span></span></a></li>
                <li><a href="/zy?are=tl">讨论</a></li>
                <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><span class="fly-mid"></span></li>


                <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><a
                        href="/user/user_message#index">我发表的贴</a></li>
                <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><a
                        href="/user/collects">我收藏的贴</a></li>
            </ul>

            <div class="fly-column-right layui-hide-xs">
                <a href="/user/add" class="layui-btn">发表新帖</a>
            </div>
            <div class="layui-hide-sm layui-show-xs-block"
                 style="margin-top: -10px; padding-bottom: 10px; text-align: center;">
                <a href="/user/add" class="layui-btn">发表新帖</a>
            </div>
        </div>
    </div>
</div>

<div class="layui-container">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md8 content detail">
            <div class="fly-panel detail-box">
                <h1>{{ news.title }}</h1>
                <div class="fly-detail-info">
                    <!-- <span class="layui-badge">审核中</span> -->
                    <span class="layui-badge layui-bg-green fly-detail-column">{{ news.category.name }}</span>

                    <div class="fly-admin-box" data-id="123">
                    </div>
                    <span class="fly-list-nums">
            <a href="#comment"><i class="iconfont" title="回答">&#xe60c;</i> {{ news.comment_num }}</a>
            <i class="iconfont" title="人气">&#xe60b;</i> {{ news.click_nums }}
          </span>
                </div>
                <div class="detail-about">
                    <a class="fly-avatar" href="/user/home?u={{ news.user_id }}">
                        <img src="{{ news.user.images_url }}"
                             alt="{{ news.user.username }}">
                    </a>
                    <div class="fly-detail-user">
                        <a href="/user/home?u={{ news.user_id }}" class="fly-link">
                            <cite>{{ news.user.username }}</cite>
                            {% if news.user.is_vip != 0 %}
                                <i class="layui-badge fly-badge-vip">VIP{{ news.is_vip }}</i>
                            {% endif %}

                        </a>
                        <span>{{ news.modify_time.strftime("%Y-%m-%d %H:%M") }}</span>
                    </div>
                    <div class="detail-hits" id="LAY_jieAdmin" data-id="123">
                        <span style="padding-right: 10px; color: #FF7200">悬赏：{{ news.award }}飞吻</span>
                        <!--?                        当用户已经登录了并且这个帖子是他的时候才显示编辑-->
                        <!--?                        <span class="layui-btn layui-btn-xs jie-admin" type="edit"><a href="add.html">编辑</a></span>-->
                        {% if collection == "1" %}
                            <span class="layui-btn layui-btn-xs jie-admin" type="edit"><a onclick="shoc({{ news.id }})">收藏</a></span>
                            <input type="hidden" id="sc" value="do">
                        {% else %}
                            <span class="layui-btn jie-admin" type="edit"><a
                                    onclick="shoc({{ news.id }})">已收藏</a></span>
                            <input type="hidden" id="sc" value="undo">
                        {% endif %}
                    </div>

                    <li value="{{ news.id }}" class="comment_input" id="tie_id"></li>
                </div>
                {{ news.content | safe }}
            </div>

            <div class="fly-panel detail-box" id="flyReply">
                <fieldset class="layui-elem-field layui-field-title" style="text-align: center;">
                    <legend>回帖</legend>
                </fieldset>

                <ul class="jieda" id="jieda">

                    {% for i in comment %}
                        <li data-id="111">
                            <a name="item-1111111111"></a>
                            <div class="detail-about detail-about-reply">
                                <a class="fly-avatar" href="/user/home?u={{ i.belong_user.id }}">
                                    <img src="{{ i.belong_user.images_url }}"
                                         alt=" ">
                                </a>
                                <div class="fly-detail-user">
                                    <a href="/user/home?u={{ i.belong_user.id }}" class="fly-link">
                                        <cite>{{ i.belong_user.username }}</cite>
                                    </a>
                                </div>
                                <div class="detail-hits">
                                    <span>{{ i.create_time.strftime("%Y-%m-%d %H:%M") }}</span>
                                </div>
                            </div>
                            <div class="detail-body jieda-body photos">
                                {% if i.to_user %}
                                    <p>
                                        回复<a
                                            href="/user/home?u={{ i.to_user }}">{{ i.to_user.belong_user.username }}</a>的评论：{{ i.to_user.content | safe }}
                                    </p>
                                {% endif %}
                                {{ i.content | safe }}

                            </div>
                            <div class="jieda-reply comment_list_con">
                              <span class="jieda-zan" type="zan">
                                <i class="iconfont icon-zan" onclick="bbb({{ i.id }})"></i>
                                <em>{{ i.like_num }}</em>
                              </span><i class="iconfont icon-svgmoban53"></i>
                                <a href="javascript:;" class="comment_reply" id="diji{{ i.id }}">回复</a>
                                <from class="reply_form" style="display: none;">
                                    <div class="layui-form layui-form-pane">

                                        <div class="layui-form-item layui-form-text">
                                            <a name="comment"></a>
                                            <div class="layui-input-block">
                                                <textarea id="L_content{{ i.id }}" name="content" required
                                                          lay-verify="required"
                                                          placeholder="请输入要回复的内容" class="layui-textarea fly-editor"
                                                          style="height: 150px;"></textarea>
                                                <input id="reply_id{{ i.id }}" value="{{ i.id }}" hidden>
                                                <button class="layui-btn" onclick="aaa({{ i.id }})"
                                                        id="comment_form" data-news-id="">提交回复
                                                </button>
                                                <button class="layui-btn fr" onclick="dianji({{ loop.index }})">取消
                                                </button>

                                            </div>
                                        </div>
                                    </div>
                                </from>
                            </div>
                        </li>
                    {% endfor %}
                    {% if not comment %}
                        <li class="fly-none">消灭零回复</li>
                    {% endif %}
                </ul>

                <div class="layui-form layui-form-pane">
                    <form action="">
                        <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
                        <div class="layui-form-item layui-form-text">
                            <a name="comment"></a>
                            <div class="layui-input-block">
                                <textarea id="L_content111" name="content" required lay-verify="required"
                                          placeholder="请输入内容" class="layui-textarea fly-editor"
                                          style="height: 150px;"></textarea>
                                <input id="reply_id111" value="None" hidden>
                                <input class="layui-btn fr" onclick="aaa(111)" style="width:120px;" value="提交" readonly>
                            </div>

                        </div>
                        <div>
                            <input type="hidden" name="jid" value="123">
                        </div>
                    </form>
                </div>
            </div>

            <div style="margin-left: 18%">


            </div>
        </div>

        <div class="fly-footer">
            <div class="layui-col-md4">

                <div class="fly-panel">
                    <h3 class="fly-panel-title">温馨通道</h3>
                    <ul class="fly-panel-main fly-list-static">
                        <li>
                            <a href="http://fly.layui.com/jie/4281/" target="_blank">layui 的 GitHub 及 Gitee (码云)
                                仓库，欢迎Star</a>
                        </li>
                        <li>
                            <a href="http://fly.layui.com/jie/5366/" target="_blank">
                                layui 常见问题的处理和实用干货集锦
                            </a>
                        </li>
                        <li>
                            <a href="http://fly.layui.com/jie/4281/" target="_blank">layui 的 GitHub 及 Gitee (码云)
                                仓库，欢迎Star</a>
                        </li>
                        <li>
                            <a href="http://fly.layui.com/jie/5366/" target="_blank">
                                layui 常见问题的处理和实用干货集锦
                            </a>
                        </li>
                        <li>
                            <a href="http://fly.layui.com/jie/4281/" target="_blank">layui 的 GitHub 及 Gitee (码云)
                                仓库，欢迎Star</a>
                        </li>
                    </ul>
                </div>


                <dl class="fly-panel fly-list-one">
                    <dt class="fly-panel-title">今年热议前10条</dt>
                    {% for i in new %}
                        <dd>
                            <a href="/jie/detail?u={{ i.id }}">{{ i.title }}</a>
                            <span><i class="iconfont icon-pinglun1"></i> {{ i.comment_num }}</span>
                        </dd>
                    {% endfor %}
                    {#                <dd>#}
                    {#                    <a href="jie/detail.html">基于 layui 的极简社区页面模版</a>#}
                    {#                    <span><i class="iconfont icon-pinglun1"></i> 16</span>#}
                    {#                </dd>#}

                    <!-- 无数据时 -->
                    <!--
                    <div class="fly-none">没有相关数据</div>
                    -->
                </dl>

                <div class="fly-panel">
                    <div class="fly-panel-title">
                        这里可作为广告区域
                    </div>
                    <div class="fly-panel-main">
                        <a href="http://layim.layui.com/?from=fly" target="_blank" class="fly-zanzhu"
                           time-limit="2017.09.25-2099.01.01" style="background-color: #5FB878;">LayIM 3.0 - layui
                            旗舰之作</a>
                    </div>
                </div>

                <div class="fly-panel fly-link">
                    <h3 class="fly-panel-title">友情链接</h3>
                    <dl class="fly-panel-main">
                        <dd><a href="http://www.layui.com/" target="_blank">layui</a>
                        <dd>
                        <dd><a href="http://layim.layui.com/" target="_blank">WebIM</a>
                        <dd>
                        <dd><a href="http://layer.layui.com/" target="_blank">layer</a>
                        <dd>
                        <dd><a href="http://www.layui.com/laydate/" target="_blank">layDate</a>
                        <dd>
                        <dd>
                            <a href="mailto:1060377319@qq.com?subject=%E7%94%B3%E8%AF%B7Fly%E7%A4%BE%E5%8C%BA%E5%8F%8B%E9%93%BE"
                               class="fly-link">申请友链</a>
                        <dd>
                    </dl>
                </div>

            </div>

        </div>
    </div>
</div>
<div class="fly-footer">
    <p><a href="#">小宅论坛</a> 2019 &copy; <a href="#">小宅娱乐出品</a>皖ICP备19010957号-1</p>
</div>
<script src="{{ static('js/layui/jquery-3.3.1.min.js') }}"></script>
<script src="{{ static('js/layui/layui.js') }}"></script>
<script src="{{ static('js/layui/jwt.js') }}"></script>
<script src="{{ static('res/mods/detail.js') }}"></script>
<script>
    $(function () {
        hasUser();

    });

    function hasUser() {

        let jwt = getJwtToken();
        if (jwt) {
            $.ajax({
                type: "get",
                url: HOST_URL + "user/getUser",
                dataType: "json",
                headers: createAuthorizationTokenHeader(),
                success: function (data) {
                    console.log(data);
                    if (data) {
                        let appendVal = `
                            <li class="layui-nav-item">
                              <a class="fly-nav-avatar" href="javascript:;">
                                <cite class="layui-hide-xs">${data.username}</cite>
<!--                                <i class="iconfont icon-renzheng layui-hide-xs" title="认证信息：layui 作者"></i>-->
                                <i class="layui-badge fly-badge-vip layui-hide-xs">VIP${data.level}</i>
                                <img src="${data.picture}">
                              </a>
                              <dl class="layui-nav-child">
                                <dd><a href="../user/set"><i class="layui-icon">&#xe620;</i>基本设置</a></dd>
                                <dd><a href="../user/message"><i class="iconfont icon-tongzhi" style="top: 4px;"></i>我的消息</a></dd>
                                <dd><a href="../user/home?u={{user.id}}"><i class="layui-icon" style="margin-left: 2px; font-size: 22px;">&#xe68e;</i>我的主页</a></dd>
                                <hr style="margin: 5px 0;">
                                <dd><a href="javascript:logout();" style="text-align: center;">退出</a></dd>
                              </dl>
                            </li>
                        `;

                        $("#ul_user").html(appendVal);
                    }
                }
            })
        }
    }

    //  注销
    function logout() {
        layer.confirm("真的要注销吗?", () => {

            removeJwtToken();
            layer.msg("注销成功", {time: 1000}, function () {
                location.reload();
            });
        })
    }

    function dianji(e) {
        document.getElementById("diji" + e).click()
    }

    function aaa(e) {

        var content = document.getElementById("L_content" + e).value;

        var reply_id = document.getElementById("reply_id" + e).value;   // 获取这条评论回复的是谁的评论

        var news_id = document.getElementById("tie_id").value;

        if (!content) {
            //如果回复的内容没有数据则弹窗
            alert("你还没有评论。。。。");
            return;
        }
        var params = {
            "content": content,
            "reply_id": reply_id,
            "news_id": news_id
        };

        $.ajax({
            url: "/user/reply",
            type: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            success: function (resp) {
                if (resp.status == "0") {
                    location = location
                } else if (resp.status == "8009") {
                    alert(resp.msg)
                    location.href = "/user/index"
                } else if (resp.errno == "9006") {
                    alert(resp.msg)
                    location.href = "/user/index"
                } else {
                    alert(resp.msg)
                    alert("2")
                }
            }
        })
    }

    function bbb(e) {

        var content = e;


        var params = {
            "id": content
        };

        $.ajax({
            url: "/user/like",
            type: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            success: function (resp) {
                if (resp.status == "0") {
                    location = location
                } else if (resp.status == "8009") {
                    alert(resp.msg)
                    location.href = "/login"
                } else if (resp.errno == "9006") {
                    alert(resp.msg)
                    location.href = "/user/index"
                } else {
                    alert("1");
                    alert(resp.msg)
                }
            }
        })
    }

    function shoc(e) {
        var zl = document.getElementById("sc").value;
        var params = {
            "zl": zl,
            "news_id": e
        };
        $.ajax({
            url: "/user/collect",
            type: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            success: function (resp) {
                if (resp.errno == "0") {
                    location = location
                } else {
                    alert(resp.msg)
                }
            }
        })
    }

    layui.cache.page = 'user';
    layui.cache.user = {
        username: '游客'
        , uid: -1
        , avatar: '../../res/images/avatar/00.jpg'
        , experience: 83
        , sex: '男'
    };
    layui.config({
        version: "3.0.0"
        , base: '../../static/res/mods/'
    }).extend({
        fly: 'index'
    }).use('fly');
</script>

</body>
</html>